/* 
 * File:   User.cpp
 * Author: switch
 * 
 * Created on 26 janvier 2013, 13:25
 */

#include "User.h"

User::User() {
    name="user";
}

void User::SetListOfTasksLists(list<ListOfTask*> listOfTasksLists) {
    this->listOfTasksLists = listOfTasksLists;
}

list<ListOfTask*> User::GetListOfTasksLists() const {
    return listOfTasksLists;
}

list<ListOfTask*> User::GetTemplates() const {
    return templates;
}

 ListOfTask* User::GetListByName(string name) {

    for (std::list<ListOfTask*>::iterator it = listOfTasksLists.begin(); it != listOfTasksLists.end(); ++it) {
        ListOfTask *tmpListOfTask = *it;
        
        if(tmpListOfTask->getName()==name) {
            return tmpListOfTask;
        }
        
        
    }
     
    return NULL;
}
 
 ListOfTask* User::GetTemplateByName(string name) {

    for (std::list<ListOfTask*>::iterator it = templates.begin(); it != templates.end(); ++it) {
        ListOfTask *tmpListtemplate = *it;
        
        if(tmpListtemplate->getName()==name) {
            return tmpListtemplate;
        }
        
        
    }
     
    return NULL;
}


//Gestion de la liste des taches
void User::addList(ListOfTask* t) {
    listOfTasksLists.push_back(t);
}

void User::removeList(ListOfTask* t) {
    listOfTasksLists.remove(t);
}

void User::addTemplate(ListOfTask* t) {
    templates.push_back(t);
}

void User::removeTemplate(ListOfTask* t) {
    templates.remove(t);
}

void User::SetName(string name) {
    this->name = name;
}

string User::GetName() const {
    return name;
}


string User::toString() {
    string res = this->GetName()+" : (";

    for (std::list<ListOfTask*>::iterator it = listOfTasksLists.begin(); it != listOfTasksLists.end(); ++it) {
        ListOfTask *tmpListOfTask = *it;
        res+=tmpListOfTask->toString();
    }
   
    return res+")";
}
